package com.framework.thread;

import com.framework.util.SystemUtil;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2022/11/3 15:57
 */
public class ReqComTool {

    public static ReqComDTO getReqComDTO() {
        return ReqComHold.getReqCom();
    }

    public static void removeReqComDTO() {
        ReqComHold.removeReqCom();
    }

    public static void buildPshcpTraceId() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        if (reqComDTO == null) {
            reqComDTO = new ReqComDTO();
        }
        reqComDTO.setPshcpTraceId(SystemUtil.getUUID());
        ReqComHold.setReqCom(reqComDTO);
    }

    public static void buildReqComDTO2Session(String token, Long sessionId, Integer terminal, Integer userType, Long userId) {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        if (reqComDTO == null) {
            reqComDTO = new ReqComDTO();
        }
        reqComDTO.setToken(token);
        reqComDTO.setSessionId(sessionId);
        reqComDTO.setTerminal(terminal);
        reqComDTO.setUserType(userType);
        reqComDTO.setUserId(userId);
        ReqComHold.setReqCom(reqComDTO);
    }

    public static Long getSessionId() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        return reqComDTO == null ? null : reqComDTO.getSessionId();
    }


    public static void buildSessionStatus(Integer sessionStatus) {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        if (reqComDTO == null) {
            reqComDTO = new ReqComDTO();
        }
        reqComDTO.setSessionStatus(sessionStatus);
        ReqComHold.setReqCom(reqComDTO);
    }

    public static int getSessionStatus() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        return reqComDTO == null || reqComDTO.getSessionStatus() == null ? 1 : reqComDTO.getSessionStatus();
    }

    public static void buildReqBody(String reqBody) {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        if (reqComDTO == null) {
            reqComDTO = new ReqComDTO();
        }
        reqComDTO.setReqBody(reqBody);
        ReqComHold.setReqCom(reqComDTO);
    }


    public static String getReqBody() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        return reqComDTO == null ? null : reqComDTO.getReqBody();
    }

    public static String getToken() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        return reqComDTO == null ? null : reqComDTO.getToken();
    }

    public static Integer getTerminal() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        return reqComDTO == null ? null : reqComDTO.getTerminal();
    }

    public static Integer getUserType() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        return reqComDTO == null ? null : reqComDTO.getUserType();
    }

    public static Long getUserId() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        return reqComDTO == null ? null : reqComDTO.getUserId();
    }

    public static String getPshcpTraceId() {
        ReqComDTO reqComDTO = ReqComHold.getReqCom();
        return reqComDTO == null ? null : reqComDTO.getPshcpTraceId();
    }
}
